#ifndef __HELPER_SLAVE_H__
#define __HELPER_SLAVE_H__

#include "args.h"
#include "task.h"
#define HELPER_BUFF_SIZE 16 //buffsize=32的时候在BLK=8时执行子任务的时候会出错
#define NT 64
#define BUFFER1_OWN 0
#define BUFFER2_OWN 1
#define TOP_WINDOW 2048  //取2048则从核LDM不够
#define SEND_TASK_WINDOW 512   //取2048则从核LDM不够
// extern volatile __thread int helper_init_done;
// extern __uncached volatile int slave_init_done=0;
// extern volatile __thread struct slave_help_buff slave_buffer[NT];
//extern __uncached struct slave_help_buff buffer[NT];


//extern __thread_local_fix slave_work_buffer sl_buffers[64][HELPER_BUFFER_COUNT];
//extern slave_table tables[64];

extern void worker_help_func();
void init_slave_buffer();

#ifndef MULZTI_CORE_C
typedef struct slave_helper_item {  //消息传递四元组
    volatile void *item_address;
    volatile unsigned long item_hash;
    volatile struct DataAccess *item_access;
    volatile int item_id;
} slave_helper_item;  //依赖域哈希表
#else
typedef struct slave_helper_item {  //消息传递五元组
    volatile void *item_address;
    volatile struct DataAccess *item_access;
    volatile struct ci_task *item_task;
    volatile int item_type;  
    volatile int item_id;
} slave_helper_item;  //依赖域哈希表
#endif

typedef struct slave_work_buffer {
    volatile slave_helper_item items[SLAVE_BUF_SIZE];
    volatile int idx;
} slave_work_buffer;
typedef struct latent_top {
    volatile void *top_task[TOP_WINDOW];
    volatile int top_index;
} latent_top;

struct slave_help_buff
{
    volatile int head ;
    volatile int tail ;
    struct slave_helper_item base[HELPER_BUFF_SIZE];
};
struct top_level_buff
{
    // volatile int top_num ;
    volatile int head ;
    volatile int tail ;
    struct task *top_task[HELPER_BUFF_SIZE];
};
struct buffer_tasks {  
    struct task *Thead;  // 链表的头指针  
    struct task *Ttail;  // 链表的尾指针（可选，用于快速添加）  
}; 
#endif
